/*     */ package com.qmsk.business.manage.user.controller;
/*     */ 
/*     */ import com.qmsk.business.info.shop.dao.ShopUserDAO;
/*     */ import com.qmsk.business.manage.mpCity.dao.MpCityDAO;
/*     */ import com.qmsk.business.manage.user.dao.UserDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.qmsk.session.UserSessionInfo;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.crypt.AESUtils;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.gson.out.GsonEbRstLong;
/*     */ import com.utils.http.HttpGsonPtUtils;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/user"})
/*     */ public class UserController
/*     */ {
/*  42 */   private static final Logger logger = Logger.getLogger(UserController.class);
/*     */ 
/*     */   @Autowired
/*     */   private UserDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private ShopUserDAO shopUserDao;
/*     */ 
/*     */   @Autowired
/*     */   private MpCityDAO mpCityDAO;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  78 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  80 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(shopId, nPageIdx, 
/*  81 */         nPageSize);
/*  82 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  84 */       logger.error(e);
/*  85 */       ResponseUtils.setErrorMsgResponse(
/*  86 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/*  87 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/findUserByOpenId"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void findUserByOpenId(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 102 */       String openId = RequestUtils.getString(request, "openId");
/* 103 */       GsonEbRst gsonEbRst = this.dao.findUserByOpenId(openId);
/* 104 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 106 */       logger.error(e);
/* 107 */       ResponseUtils.setErrorMsgResponse(
/* 108 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/* 109 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/hostList/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 118 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 120 */       GsonEbRst gsonEbRst = this.dao.getGsonOfHost(shopId, nPageIdx, 
/* 121 */         nPageSize);
/* 122 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 124 */       logger.error(e);
/* 125 */       ResponseUtils.setErrorMsgResponse(
/* 126 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/* 127 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/departName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getOneDepart(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 139 */     String userId = UserSessionInfo.getUserIdOfSession(request);
/*     */     try {
/* 141 */       GsonEbRst gsonEbRst = this.dao.getGsonOfUserId(userId);
/* 142 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 144 */       logger.error(e);
/* 145 */       ResponseUtils.setErrorMsgResponse(
/* 146 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/* 147 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private Long getPtCustIdOfInsertPt(String sGsonInData, Long shopId, String dutyName, HttpServletResponse response)
/*     */     throws Exception
/*     */   {
/* 177 */     String sData = "data=" + sGsonInData + "&" + "shopId" + 
/* 178 */       "=" + String.valueOf(shopId) + "&dutyName=" + dutyName + "&isUser=1";
/* 179 */     String url = "ptcust/insert";
/* 180 */     GsonEbRstLong rst = HttpGsonPtUtils.getEbRstLong(url, sData, response);
/* 181 */     if (rst != null) {
/* 182 */       return rst.getResult();
/*     */     }
/* 184 */     return null;
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 266 */     String sGsonInData = request.getParameter("data");
/* 267 */     String shopId = request.getParameter("shopId");
/* 268 */     int nResult = 0;
/* 269 */     String mp = null;
/* 270 */     String loginName = null;
/* 271 */     GsonHeadOneRow g = GsonHeadOneRow.jsonStrToObject(sGsonInData);
/*     */     try {
/* 273 */       loginName = (String)g.getValueOfName("LoginName");
/* 274 */       if ((StringUtils.isNotEmpty(loginName)) && 
/* 275 */         (this.dao.getIsLoginName(loginName).intValue() > 0)) {
/* 276 */         ResponseUtils.setErrorMsgResponse("内部人员已有相同登录名", response);
/* 277 */         return;
/*     */       }
/*     */ 
/* 280 */       mp = (String)g.getValueOfName("Mp");
/* 281 */       if (!(StringUtils.isEmpty(mp))) {
/* 282 */         if (this.dao.existUserOfMp(AESUtils.getInst().encrypt(mp))) {
/* 283 */           ResponseUtils.setErrorMsgResponse("手机号为" + mp + "的人员已存在", 
/* 284 */             response);
/* 285 */           return;
/*     */         }
/* 287 */         String StrNum = StringUtils.substring(mp, 0, 7);
/* 288 */         if (!(this.mpCityDAO.getCheckMp(StrNum).booleanValue())) {
/* 289 */           ResponseUtils.setErrorMsgResponse("手机号码不合法", response);
/* 290 */           return;
/*     */         }
/*     */       }
/*     */ 
/* 294 */       nResult = this.dao.insertGsonHeadOneRow(g);
/* 295 */       Long id = this.dao.getLastId();
/* 296 */       if ((id != null) && (id.longValue() > 0L)) {
/* 297 */         nResult = this.shopUserDao
/* 298 */           .insertParams(new Object[] { shopId, id, Integer.valueOf(1) }).intValue();
/*     */       }
/* 300 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 301 */         RequestUtils.getSqlInsertErrorMessage("info.cust.label", request), 
/* 302 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 305 */       logger.error(e);
/*     */ 
/* 308 */       ResponseUtils.setErrorMsgResponse(
/* 309 */         RequestUtils.getSqlInsertErrorMessage("info.cust.label", request), 
/* 310 */         response);
/*     */     } finally {
/* 312 */       if (nResult <= 0)
/* 313 */         DbConnection.rollback();
/*     */       else
/* 315 */         DbConnection.commit();
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 352 */     int nResult = 0;
/* 353 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 355 */       String[] strParams = id.split(",");
/* 356 */       nResult = this.dao.deleteParams(strParams);
/* 357 */       if (nResult > 0) {
/* 358 */         nResult = this.shopUserDao.deleteParams(strParams);
/*     */       }
/* 360 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 361 */         RequestUtils.getSqlDeleteErrorMessage("info.cust.label", request), 
/* 362 */         response);
/*     */     } catch (Exception e) {
/* 364 */       logger.error(e);
/* 365 */       ResponseUtils.setErrorMsgResponse(
/* 366 */         RequestUtils.getSqlDeleteErrorMessage("info.cust.label", request), 
/* 367 */         response);
/*     */     } finally {
/* 369 */       if (nResult <= 0)
/* 370 */         DbConnection.rollback();
/*     */       else
/* 372 */         DbConnection.commit();
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void updateUserPt(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 402 */       Long id = RequestUtils.getLong(request, "id");
/* 403 */       String dutyName = this.dao.getDutyNameOfUserId(id);
/* 404 */       if (StringUtils.isEmpty(dutyName)) {
/* 405 */         ResponseUtils.setErrorMsgResponse("该人员没有设置岗位", response);
/* 406 */         return;
/*     */       }
/* 408 */       GsonHeadOneRow g = this.dao.getUserOfUserId(id);
/* 409 */       g.autoAddHeadData("CreateFileTime", new Date());
/*     */ 
/* 411 */       Long outId = getPtCustIdOfInsertPt(g.objectToJsonStr(), ShopMap.getOutIdOfShopId(shopId), 
/* 412 */         dutyName, response);
/* 413 */       int nResult = 0;
/* 414 */       if ((outId != null) && (outId.longValue() > 0L)) {
/* 415 */         nResult = this.dao.updateOutIdOfId(outId, id);
/*     */       }
/* 417 */       if (nResult > 0) {
/* 418 */         DbConnection.commit();
/* 419 */         if (id != null) {
/* 420 */           String[] heads = { "outId" };
/* 421 */           Object[] datas = { outId };
/* 422 */           ResponseUtils.toGsonEbRst(heads, datas, response);
/* 423 */           return; }
/* 424 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 425 */           RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 426 */           response);
/*     */ 
/* 428 */         return; }
/* 429 */       DbConnection.rollback();
/* 430 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 431 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 432 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 435 */       DbConnection.rollback();
/* 436 */       logger.error(e);
/* 437 */       ResponseUtils.setErrorMsgResponse(
/* 438 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 439 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 456 */     int nResult = 0;
/* 457 */     String id = request.getParameter("id");
/* 458 */     String sGsonInData = request.getParameter("data");
/*     */     try {
/* 460 */       GsonHeadOneRow g = GsonHeadOneRow.jsonStrToObject(sGsonInData);
/* 461 */       if (g == null) {
/* 462 */         ResponseUtils.setErrorMsgResponse(
/* 463 */           RequestUtils.getReadJsonDataErrorMessage(request), 
/* 464 */           response);
/* 465 */        
/*     */       }
/*     */ 
/* 468 */       String mp = (String)g.getValueOfName("Mp");
/* 469 */       String email = (String)g.getValueOfName("Email");
/* 470 */       if (mp != null) {
/* 471 */         String StrNum = StringUtils.substring(mp, 0, 7);
/* 472 */         if (!(this.mpCityDAO.getCheckMp(StrNum).booleanValue())) {
/* 473 */           ResponseUtils.setErrorMsgResponse("手机号码不合法", response);
/* 474 */           return;
/*     */         }
/* 476 */         if (this.dao.existUserOfMp(AESUtils.getInst().encrypt(mp))) {
/* 477 */           ResponseUtils.setErrorMsgResponse("已有相同手机号", response);
/* 478 */           return;
/*     */         }
/*     */       }
/* 481 */       if (email != null) {
/* 482 */         Long count = this.dao.getUserIdOfEmail(email);
/* 483 */         if (count.longValue() > 0L) {
/* 484 */           ResponseUtils.setErrorMsgResponse("已有相同邮箱", response);
/* 485 */           return;
/*     */         }
/*     */       }
/* 488 */       nResult = this.dao.updateJsonOneRow(g, id);
/* 489 */       label315: ResponseUtils.setSqlResultResponse(nResult, 
/* 490 */         RequestUtils.getSqlUpdateErrorMessage("info.cust.label", request), 
/* 491 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 494 */       logger.error(e);
/* 495 */       ResponseUtils.setErrorMsgResponse(
/* 497 */         RequestUtils.getSqlUpdateErrorMessage("info.cust.label", 
/* 497 */         request) + ":" + e.getMessage(), response);
/*     */     } finally {
/* 499 */       if (nResult <= 0)
/* 500 */         DbConnection.rollback();
/*     */       else
/* 502 */         DbConnection.commit();
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/ps"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void updatePassword(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 520 */     int nResult = 0;
/* 521 */     String newPs = request.getParameter("newPs");
/* 522 */     String oldPs = request.getParameter("oldPs");
/*     */     try {
/* 524 */       String newPs2 = AESUtils.getInst().encrypt(newPs);
/* 525 */       String oldPs2 = AESUtils.getInst().encrypt(oldPs);
/* 526 */       Integer userId = Integer.valueOf(
/* 527 */         UserSessionInfo.getUserIdOfSession(request));
/* 528 */       if (!(this.dao.isExistsOfUserIdPassword(userId, oldPs2)))
/* 529 */         ResponseUtils.setSqlResultResponse(nResult, "原密码不正确", response);
/*     */       else {
/* 531 */         nResult = this.dao.changePs(userId, newPs2, oldPs2);
/*     */       }
/*     */ 
/* 534 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 535 */         RequestUtils.getSqlUpdateErrorMessage("info.cust.password.label", 
/* 536 */         request), response);
/*     */     } catch (Exception e) {
/* 538 */       logger.error(e);
/* 539 */       ResponseUtils.setErrorMsgResponse(
/* 541 */         RequestUtils.getSqlUpdateErrorMessage("info.cust.password.label", request) + 
/* 542 */         ":" + 
/* 543 */         e.getMessage(), response);
/*     */     } finally {
/* 545 */       if (nResult <= 0)
/* 546 */         DbConnection.rollback();
/*     */       else
/* 548 */         DbConnection.commit();
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/userList/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void getUserListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 594 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */ 
/* 596 */     Map params = new HashMap();
/* 597 */     String mp = RequestUtils.getString(request, "phone");
/* 598 */     if (StringUtils.isNotEmpty(mp)) {
/* 599 */       mp = AESUtils.getInst().encrypt(mp);
/*     */     }
/* 601 */     params.put("status", RequestUtils.getString(request, "status"));
/* 602 */     params.put("shopId", RequestUtils.getString(request, "shopId"));
/* 603 */     MapUtils.addPercentToMap(params, "mp", mp);
/* 604 */     MapUtils.addPercentToMap(params, "username", RequestUtils.getString(request, "username"));
/* 605 */     MapUtils.addPercentToMap(params, "loginname", RequestUtils.getString(request, "loginname"));
/*     */     try
/*     */     {
/* 609 */       GsonEbRst gsonEbRst = this.dao.getUserList(params, nPageIdx, 
/* 610 */         nPageSize);
/* 611 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 613 */       logger.error(e);
/* 614 */       ResponseUtils.setErrorMsgResponse(
/* 615 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/* 616 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/userById"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getUserById(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 630 */     Long id = RequestUtils.getLong(request, "id");
/*     */     try
/*     */     {
/* 634 */       Map params = new HashMap();
/* 635 */       params.put("id", id);
/* 636 */       Short paeShort = Short.valueOf((short) 1);
/* 637 */       GsonEbRst g = this.dao.getUserListByDutyID(params, Integer.valueOf(0), paeShort);
/* 638 */       ResponseUtils.setResponseResult(g, response);
/*     */     } catch (SQLException e) {
/* 640 */       logger.error(e);
/* 641 */       ResponseUtils.setErrorMsgResponse(
/* 642 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/* 643 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/userByDutyId/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getUserById(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 658 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */ 
/* 660 */     Long dutyId = RequestUtils.getLong(request, "dutyId");
/*     */     try
/*     */     {
/* 663 */       Map params = new HashMap();
/* 664 */       params.put("dutyId", dutyId);
/* 665 */       GsonEbRst g = this.dao.getUserListByDutyID(params, nPageIdx, nPageSize);
/* 666 */       ResponseUtils.setResponseResult(g, response);
/*     */     } catch (SQLException e) {
/* 668 */       logger.error(e);
/* 669 */       ResponseUtils.setErrorMsgResponse(
/* 670 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/* 671 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/userByDutyId"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getUserByIdAll(HttpServletRequest request, HttpServletResponse response) {
/* 677 */     Long dutyId = RequestUtils.getLong(request, "dutyId");
/*     */     try
/*     */     {
/* 680 */       Map params = new HashMap();
/* 681 */       params.put("dutyId", dutyId);
/* 682 */       GsonEbRst g = this.dao.getUserListByDutyID(params);
/* 683 */       ResponseUtils.setResponseResult(g, response);
/*     */     } catch (SQLException e) {
/* 685 */       logger.error(e);
/* 686 */       ResponseUtils.setErrorMsgResponse(
/* 687 */         RequestUtils.getSqlFindErrorMessage("info.cust.label", request), 
/* 688 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"insert/insertOpenId"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void login(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 698 */       String sUserName = RequestUtils.getString(request, "loginName");
/* 699 */       String pwd = RequestUtils.getString(request, "pwd");
/* 700 */       String openID = RequestUtils.getString(request, "openID");
/* 701 */       String sPs2 = AESUtils.getInst().encrypt(pwd);
/* 702 */       GsonHeadOneRow row = this.dao
/* 703 */         .getUserIdStatusOfLoginName(sUserName, sPs2);
/* 704 */       int nResult = 0;
/* 705 */       if ((row != null) && (row.isExistsData())) {
/* 706 */         Long userId = ObjectComm.objectToLong(row.getValueOfName("CustomerID"));
/* 707 */         nResult = this.dao.updateUserOpenId(openID, userId);
/* 708 */         if (nResult > 0) {
/* 709 */           this.dao.commit();
/* 710 */           ResponseUtils.setSuccessResponse(response);
/* 711 */           return; }
/* 712 */         this.dao.rollback();
/* 713 */         ResponseUtils.setErrorMsgResponse("绑定失败", response);
/*     */ 
/* 715 */         return; }
/* 716 */       ResponseUtils.setErrorMsgResponse("登陆名或密码错误", response);
/*     */     }
/*     */     catch (Exception e) {
/* 719 */       this.dao.rollback();
/* 720 */       logger.error(e);
/* 721 */       ResponseUtils.setErrorMsgResponse("绑定失败", 
/* 722 */         response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.manage.user.controller.UserController
 * JD-Core Version:    0.5.3
 */